home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Docs / Includes / UEditionDocument.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  18.1 KB  |  562 lines  |  [TEXT/MPS ]

  1. // UEditionDocument.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UEDITIONDOCUMENT__
  5. #define __UEDITIONDOCUMENT__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __UADORNERS__
  10. #include "UAdorners.h"
  11. #endif
  12.  
  13. #ifndef __UBEHAVIOR__
  14. #include "UBehavior.h"
  15. #endif
  16.  
  17. #ifndef __UCOMMAND__
  18. #include "UCommand.h"
  19. #endif
  20.  
  21. #ifndef __UFILEBASEDDOCUMENT__
  22. #include "UFileBasedDocument.h"
  23. #endif
  24.  
  25. #ifndef __UGEOMETRY__
  26. #include "UGeometry.h"
  27. #endif
  28.  
  29. #ifndef __ULISTITERATOR__
  30. #include "UListIterator.h"
  31. #endif
  32.  
  33. // Toolbox
  34.  
  35. #ifndef __EDITIONS__
  36. #include <Editions.h>
  37. #endif
  38.  
  39.  
  40. //----------------------------------------------------------------------------------------
  41. // Edition Manager menu command constants
  42. //----------------------------------------------------------------------------------------
  43.  
  44. const CommandNumber cCreatePublisher = 601;        // the user has selected "Create
  45.                                                 // Publisher" from the Edit menu
  46.  
  47. const CommandNumber cSubscribeTo = 602;            // the user has selected Subscribe to from
  48.                                                 // the Edit menu
  49.  
  50. const CommandNumber cOptions = 603;                // the user has selected a publisher in
  51.                                                 // the document and then selected
  52.                                                 // Publisher Options from the Edit menu,
  53.                                                 // OR, the user has selected a subscriber
  54.                                                 // in the document and then selected
  55.                                                 // Subscriber Options from the Edit menu
  56.  
  57. const CommandNumber cBorders = 604;                // the user has selected Show/ Hide Borders
  58.                                                 // from the Edit menu
  59.  
  60. const CommandNumber cStopAllEditions = 605;        // the user has selected Stop all Editions
  61.                                                 // from the Edit menu
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // Edition Manager command constants
  65. //----------------------------------------------------------------------------------------
  66.  
  67. const CommandNumber cCancelPublisher = 606;        // the user canceled this publisher
  68.  
  69. const CommandNumber cCancelSubscriber = 607;    // the user canceled this subscriber
  70.  
  71. //----------------------------------------------------------------------------------------
  72. // miscellaneous constants
  73. //----------------------------------------------------------------------------------------
  74.  
  75. const IDType kSectionBehavior = 'sect';
  76.  
  77. const IDType kSubscriberAdornerID = 'subs';
  78.  
  79. const IDType kPublisherAdornerID = 'publ';
  80.  
  81. //----------------------------------------------------------------------------------------
  82. // Forward and external class declarations. 
  83. //----------------------------------------------------------------------------------------
  84.  
  85. class TDesignator;
  86. class TFile;
  87. class TList;
  88. class TPublisher;
  89. class TSection;
  90. class TSectionList;
  91. class TSubscriber;
  92. class TView;
  93. class TEditionDocument;
  94.  
  95.  
  96. //----------------------------------------------------------------------------------------
  97. // CSectionIterator
  98. //----------------------------------------------------------------------------------------
  99.  
  100. class CSectionIterator : public CObjectIterator
  101. {
  102. public:
  103.     CSectionIterator(TEditionDocument* itsDocument,
  104.                      ArrayIndex itsLowBound, ArrayIndex itsHighBound,
  105.                      Boolean itsForward);
  106.  
  107.     CSectionIterator(TEditionDocument* itsDocument, Boolean itsForward);
  108.  
  109.     CSectionIterator(TEditionDocument* itsDocument);
  110.  
  111.     CSectionIterator(TSectionList* itsSectionList);
  112.     
  113.     virtual ~CSectionIterator();
  114.     
  115.     TSection* CurrentSection();
  116.         // returns the current section
  117.     
  118.     TSection* FirstSection();
  119.         // Resets the iteration to begin again and return the first section in the iteration
  120.  
  121.     TSection* NextSection();
  122.         // advances the iteration and then returns the section
  123. };
  124.  
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // TFileBasedDocument
  128. //----------------------------------------------------------------------------------------
  129.  
  130. class TEditionDocument : public TFileBasedDocument
  131. {
  132.     MA_DECLARE_CLASS;
  133.     
  134. public:
  135.     TSectionList* fSectionList;                    //  list of TSection objects
  136.  
  137.     Boolean fStopAllEditions;                    //  false by default
  138.  
  139.     Boolean fShowSectionBorders;                //  true by default
  140.  
  141.     Boolean fNewPublishers;                        //  are there any new publishers?
  142.  
  143.     short fNextEditionNumber;                    //  number used in "Untitled-n"
  144.  
  145.     OSType fEditionCreator;                        // creator for publisher edition container
  146.                                                 // file
  147.  
  148.     //------------------------------------------------------------------------------------
  149.     // constructor/destructor methods
  150.     //------------------------------------------------------------------------------------
  151.  
  152.     TEditionDocument();
  153.         // Constructor
  154.         
  155.     void IEditionDocument(TFile* itsFile,
  156.                                          const OSType itsScrapType,
  157.                                          const OSType editionCreator);
  158.         // initializes this object
  159.  
  160.     virtual ~TEditionDocument();
  161.         // frees this object
  162.  
  163.     virtual void FreeData();
  164.         // frees the fSectionList
  165.  
  166.  
  167.     //------------------------------------------------------------------------------------
  168.     // saving documents
  169.     //------------------------------------------------------------------------------------
  170.  
  171.     virtual void Close();
  172.         // For the case in which the document's change count = 0, but there are "dirty"
  173.         // sections, need to ask the user whether to save the document.
  174.  
  175.     virtual short PoseNewPublishersAlert();
  176.         // Warns the user that he is about to close a document that hasn't been saved in
  177.         // which he has created a new publisher. The user hasn't modified the document's
  178.         // data.
  179.  
  180.     virtual short PoseMultPublishersAlert(TSection* aSection);
  181.         // Warns the user that he is creating multiple publishers to the same edition.
  182.  
  183.     virtual short PoseSavingMultPublishersAlert(TSection* aSection);
  184.         // Warns the user that he is saving multiple publishers to the same edition.
  185.  
  186.     virtual void Abandon();
  187.         // Calls TSection.Delete on all dirty sections.
  188.  
  189.     virtual void DoNeedDiskSpace(TFile* itsFile,
  190.                                         long& dataForkBytes,
  191.                                         long& rsrcForkBytes);
  192.         // Bytes required to store SAVE file(s) on disk. When called, both parameters are
  193.         // set to 0 for you.
  194.  
  195.     virtual void DoWrite(TFile* aFile, Boolean makingCopy);
  196.         // writes out the sections and edition doc settings
  197.  
  198.     virtual void DoWriteSettings(TFile* aFile);
  199.         // writes out the edition doc settings (Show/ Hide Border, Stop All Editions)
  200.  
  201.     virtual void DoRead(TFile* aFile, Boolean forPrinting);
  202.         // reads in the sections and edition doc settings
  203.  
  204.     virtual void DoReadSettings(TFile* aFile);
  205.         // reads in the edition doc settings (Show/ Hide Border, Stop All Editions)
  206.  
  207.     virtual void DoReadPublisher(TFile* aFile, short theID);
  208.         // reads in a given publisher
  209.  
  210.     virtual void DoReadSubscriber(TFile* aFile, short theID);
  211.         // reads in a given subscriber
  212.  
  213.     //------------------------------------------------------------------------------------
  214.     // Revert
  215.     //------------------------------------------------------------------------------------
  216.  
  217.     virtual void RevertDocument();
  218.         // Calls Abandon() and then Inherited.
  219.  
  220.     //------------------------------------------------------------------------------------
  221.     // Accessors
  222.     //------------------------------------------------------------------------------------
  223.  
  224.     virtual void SetSectionBorders(Boolean state, Boolean invalidate);
  225.         // sets the value of fShowSectionBorders to state and invalidates the document's windows
  226.         // if "invalidate" is true
  227.  
  228.     virtual void SetStopAllEditions(Boolean state);
  229.         // sets the value of fStopAllEditions to state and reads in any new subscribers if "state"
  230.         // is true
  231.  
  232.     virtual OSType GetEditionCreatorSignature();
  233.         // returns the creator signature used for the edition container file
  234.  
  235.  
  236.     //------------------------------------------------------------------------------------
  237.     // menu management methods
  238.     //------------------------------------------------------------------------------------
  239.  
  240.     virtual void DoMenuCommand(CommandNumber aCommandNumber);
  241.  
  242.     virtual void DoSetupMenus();
  243.  
  244.     virtual Boolean CanPublishSelection();
  245.  
  246.     virtual Boolean CanSubscribe();
  247.  
  248.  
  249.     //------------------------------------------------------------------------------------
  250.     // edition manager support
  251.     //------------------------------------------------------------------------------------
  252.  
  253.     virtual void DoAddSectionBehavior(TView* itsView);
  254.         // creates and adds a TSectionBehavior to implement the Ed Mgr shortcuts.
  255.  
  256.     virtual void DoNewPublisher();
  257.  
  258.     virtual TPublisher* DoMakePublisher(TDesignator* itsDesignator,
  259.                                                SectionHandle itsSectionHandle,
  260.                                                short itsSectionID);
  261.  
  262.  
  263.     virtual void DoNewPublisherDialog(NewPublisherReply& reply);
  264.  
  265.     virtual void DoMakePreview(TDesignator* itsDesignator,
  266.                                       FormatType& previewFormat,
  267.                                       Handle& preview);
  268.     
  269.     virtual void DisposeOfPreview(NewPublisherReply& reply);
  270.         // Called from DoNewPublisher.  Default implementation diposes of the view
  271.         // if it is of type 'TEXT' or 'PICT'.  Override this method to dispose of
  272.         // your own special preview type.
  273.  
  274.     virtual void DoNewSubscriber();
  275.  
  276.     virtual TSubscriber* DoMakeSubscriber(TDesignator* itsDesignator,
  277.                                                  SectionHandle itsSectionHandle,
  278.                                                  short itsSectionID);
  279.  
  280.     virtual void DoNewSubscriberDialog(NewSubscriberReply& reply);
  281.  
  282.     virtual void DoSectionOptions();
  283.         // poses the publisher or subscriber options dialog depending on what
  284.         // GetSelectedSection returns
  285.  
  286.     virtual FormatType GetPublishPreference();
  287.         // return 'PICT' to publish 'PICT' first, return 'TEXT' to publish 'TEXT' first
  288.  
  289.     virtual SignedByte GetSubscriberFormatsMask();
  290.  
  291.     virtual void GetNextEditionName(CStr63& editionName);
  292.  
  293.     virtual void DoPublisherOptions(TPublisher* aPublisher);
  294.  
  295.     virtual void DoPublisherOptionsDialog(SectionOptionsReply& reply);
  296.  
  297.     virtual void DoSubscriberOptions(TSubscriber* aSubscriber);
  298.  
  299.     virtual void DoSubscriberOptionsDialog(SectionOptionsReply& reply);
  300.     
  301.  
  302.     //------------------------------------------------------------------------------------
  303.     // section management
  304.     //------------------------------------------------------------------------------------
  305.  
  306.     virtual void AddSection(TSection* aSection);
  307.         // adds the section to this document's section list
  308.  
  309.     virtual void AddSectionAndBorder(TSection* aSection);
  310.         // adds the section to this document's section list and calls DoAddBorder to add
  311.         // its border. This should be used when the view hierarchy has already been
  312.         // constructed and we know that have a view to attach the border to.
  313.  
  314.     virtual void CancelSection(TSection* aSection, Boolean cancel);
  315.         // calls aSection->CancelSection(cancel);
  316.  
  317.     virtual TSection* GetSelectedSection();
  318.         // This returns the currently selected section, if any. Returns NULL if > 1 section
  319.         // is currently selected.
  320.  
  321.     virtual short GetUniqueSectRsrcID();
  322.         // returns a unique 'sect' resource id for use as both the section ID and as the
  323.         // rsrc ID
  324.  
  325.     virtual Boolean IsSectionSelected(TSection* aSection);
  326.         // returns true if the given section is in the user selection
  327.  
  328.     virtual void RemoveSection(TSection* aSection);
  329.         // this method should mark document as changed so that document removes this
  330.         // section when saved (e.g. sipAlways)
  331.  
  332.     //------------------------------------------------------------------------------------
  333.     // border management
  334.     //------------------------------------------------------------------------------------
  335.  
  336.     virtual void DoPostMakeViews(Boolean forPrinting);
  337.         // Calls DoAddBorder for all sections and then calls Inherited::DoPostMakeViews().
  338.  
  339.     virtual void DoAddBorder(TSection* aSection);
  340.         // subclasses should override this to create a border to adorn this section
  341.  
  342.     virtual void DoAdjustBorder(TSection* aSection);
  343.         // subclasses should override this to adjust the border which adorn this section
  344.  
  345.     virtual void DoDeleteBorder(TSection* aSection);
  346.         // subclasses should override this to remove the border adorning this section
  347.  
  348.     virtual Boolean IsBorderShown(TSection* aSection);
  349.         // returns true if (borders are shown) or (the user selection contains aSection)
  350.  
  351. };
  352.  
  353.  
  354. //----------------------------------------------------------------------------------------
  355. // TNewSubscriberCommand: TNewSubscriberCommand creates a new subscriber and marks the
  356. // document as changed.
  357. //----------------------------------------------------------------------------------------
  358.  
  359. class TNewSubscriberCommand : public TCommand
  360. {
  361.     MA_DECLARE_CLASS;
  362.     
  363. public:
  364.     TNewSubscriberCommand();
  365.         // Empty constructor to satisfy compiler.
  366.     virtual ~TNewSubscriberCommand();
  367.         // Destructor
  368.         
  369.     void INewSubscriberCommand(CommandNumber itsCommandNumber, TDocument* itsDocument);
  370.         // initialize this command
  371.  
  372.     virtual void DoIt();
  373.         // Create a new subscriber
  374. };
  375.  
  376.  
  377. //----------------------------------------------------------------------------------------
  378. // TSectionBorderCommand: TSectionBorderCommand is an undoable command which changes the setting
  379. // for the show/ hide border option for the current document when the user chooses Hide/
  380. // Show Borders from the Edit menu
  381. //----------------------------------------------------------------------------------------
  382.  
  383. class TSectionBorderCommand : public TCommand
  384. {
  385.     MA_DECLARE_CLASS;
  386.     
  387. public:
  388.     Boolean fShowSectionBorders;                // value to set
  389.  
  390.     TSectionBorderCommand();
  391.         // Empty constructor to satisfy compiler.
  392.     virtual ~TSectionBorderCommand();
  393.         // Destructor
  394.         
  395.     void ISectionBorderCommand(CommandNumber itsCommandNumber, TDocument* itsDocument);
  396.         // initialize this command
  397.  
  398.     virtual void DoIt();
  399.         // tell the document to show or hide the borders for all sections
  400.  
  401.     virtual void UndoIt();
  402.         // tell the document to undo show or hide the borders for all sections
  403. };
  404.  
  405.  
  406. //----------------------------------------------------------------------------------------
  407. // TStopAllEditionsCommand: TStopAllEditionsCommand is an undoable command gets posted when the
  408. // user chooses Stop all Editions from the Edit menu. This command toggles the setting for
  409. // the documents fStopAllEditions field.
  410. //----------------------------------------------------------------------------------------
  411.  
  412. class TStopAllEditionsCommand : public TCommand
  413. {
  414.     MA_DECLARE_CLASS;
  415.     
  416. public:
  417.     Boolean fStopAllEditions;                    // value to set
  418.  
  419.     TStopAllEditionsCommand();
  420.         // Empty constructor to satisfy compiler.
  421.     virtual ~TStopAllEditionsCommand();
  422.         // Destructor
  423.         
  424.     void IStopAllEditionsCommand(CommandNumber itsCommandNumber, 
  425.                                             TDocument* itsDocument);
  426.         // initialize this command
  427.  
  428.     virtual void DoIt();
  429.         // tell the document to toggle the state of its fStopAllEditions flag
  430.  
  431.     virtual void UndoIt();
  432.         // tell the document to toggle the state of its fStopAllEditions flag
  433. };
  434.  
  435.  
  436. //----------------------------------------------------------------------------------------
  437. // TSectionAdorner: abstract superclass for section adorners
  438. //----------------------------------------------------------------------------------------
  439.  
  440. class TSectionAdorner : public TAdorner
  441. {
  442.     MA_DECLARE_CLASS;
  443.     
  444. public:
  445.     RgnHandle fBorderRegion;                        // the region for the section border
  446.  
  447.     TSection* fSection;                            // the section this adorner adorns
  448.  
  449.     TSectionAdorner();
  450.         // Constructor
  451.         
  452.     void ISectionAdorner(IDType itsID,
  453.                                         TSection* itsSection,
  454.                                         RgnHandle itsBorderRegion);
  455.  
  456.         // initializes the section adorner with priority kAdornAfter
  457.  
  458.     virtual ~TSectionAdorner();
  459.         // frees fBorderRegion
  460.  
  461.     virtual void InvalidateAdorner(TView* itsView); // Override
  462.         // Invalidates the adorner in the TAdornerMgr' TView.
  463.  
  464.     virtual void DrawBorder(const Pattern& whichPattern);    
  465.         // Draws the adorner's border in the TAdornerMgr' TView.
  466.  
  467. };
  468.  
  469.  
  470. //----------------------------------------------------------------------------------------
  471. // TSubscriberAdorner: A specialized adorner for imaging subscriber borders
  472. //----------------------------------------------------------------------------------------
  473.  
  474. class TSubscriberAdorner : public TSectionAdorner
  475. {
  476.     MA_DECLARE_CLASS;
  477.     
  478. public:
  479.     TSubscriberAdorner();
  480.         // Empty constructor to satisfy compiler.
  481.     virtual ~TSubscriberAdorner();
  482.         // Destructor
  483.         
  484.      void ISubscriberAdorner(IDType itsID,
  485.                                            TSubscriber* itsSubscriber,
  486.                                            RgnHandle itsBorderRegion);
  487.         // initializes the subscriber adorner
  488.  
  489.     virtual void DoHighlightSelection(TView* itsView,
  490.                                              const VRect& area,
  491.                                              HLState fromHL,
  492.                                              HLState toHL); // Override
  493.         // Adorns the selection before the view's DoHighlightSelection.
  494. };
  495.  
  496.  
  497. //----------------------------------------------------------------------------------------
  498. // TPublisherAdorner
  499. //----------------------------------------------------------------------------------------
  500.  
  501. class TPublisherAdorner : public TSectionAdorner
  502. {
  503.     MA_DECLARE_CLASS;
  504.     
  505. public:
  506.     TPublisherAdorner();
  507.         // Empty constructor to satisfy compiler.
  508.     virtual ~TPublisherAdorner();
  509.         // Destructor
  510.         
  511.     void IPublisherAdorner(IDType itsID,
  512.                                           TPublisher* itsPublisher,
  513.                                           RgnHandle itsBorderRegion);
  514.         // initializes the publisher adorner
  515.  
  516.     virtual void DoHighlightSelection(TView* itsView,
  517.                                              const VRect& area,
  518.                                              HLState fromHL,
  519.                                              HLState toHL); // Override
  520.         // Adorns the selection before the view's DoHighlightSelection.
  521.  
  522. };
  523.  
  524. //----------------------------------------------------------------------------------------
  525. // TSectionBehavior
  526. //----------------------------------------------------------------------------------------
  527.  
  528. class TSectionBehavior : public TBehavior
  529. {
  530.     MA_DECLARE_CLASS;
  531.     
  532. public:
  533.     TSectionBehavior();
  534.         // Empty constructor to satisfy compiler.
  535.     virtual ~TSectionBehavior();
  536.         // Destructor
  537.         
  538.     void ISectionBehavior(IDType itsIdentifier);
  539.  
  540.     virtual Boolean DoMouseCommand(VPoint& theMouse,
  541.                                           TToolboxEvent* event,
  542.                                           CPoint hysteresis);
  543.         // Intercepts mouse commands and traps dbl-clicks in sections.
  544.         // By default, calls Inherited.
  545.     
  546.     virtual IDType GetStandardSignature();
  547.         // Returns this class's standard signature.
  548. };
  549.  
  550.  
  551. //----------------------------------------------------------------------------------------
  552. // Externally avaibable routines
  553. //----------------------------------------------------------------------------------------
  554.  
  555. extern void InitUEditionDocument();
  556.     // call this routine to initialize this unit.
  557.  
  558.  
  559. #endif
  560.  
  561.  
  562.